<?php
namespace Action;

class EDM {
	const EDM_MODE_NONE = 0; // 邮件中没图片	const EDM_MODE_IMG = 1; // 邮件中有图片


	// 指定主机每分钟最多发送量	//static $limit = array('vip.sohu.com' => 2, 'vip.qq.com' => 2, 'vip.163.com' => 2, 'vip.sina.com' => 3, 'sina.com' => 3, 'sina.com.cn' => 3, 'msn.com' => 5, 'foxmail.com' => 5, '139.com' => 5, 'tom.com' => 5, 'live.cn' => 5, 'yahoo.com' => 5, 'yahoo.com.cn' => 5, 'yahoo.cn' => 5, '263.net' => 6, '21cn.com' => 8, 'hotmail.com' => 10, 'eyou.com' => 10, 'sohu.com' => 12, 'gmail.com' => 12, 'qq.com' => 15, 'yeah.net' => 60, '126.com' => 60, '163.com' => 60);
	static $limit = array('vip.sohu.com' => 2, 'vip.qq.com' => 2, 'vip.163.com' => 2, 'vip.sina.com' => 3, 'sina.com' => 3, 'sina.com.cn' => 3, 'msn.com' => 5, 'foxmail.com' => 5, '139.com' => 5, 'tom.com' => 5, 'live.cn' => 5, 'yahoo.com' => 5, 'yahoo.com.cn' => 5, 'yahoo.cn' => 5, '263.net' => 6, '21cn.com' => 8, 'hotmail.com' => 10, 'eyou.com' => 10, 'sohu.com' => 12, 'gmail.com' => 12, 'qq.com' => 15, 'yeah.net' => 20, '126.com' => 20, '163.com' => 20);

	static function mailer($label) {
		$mailer = array();

		if ($label == 1) {
			$mailer[] = array(10, 'lisha', 'susisoy', 'LiSha', 'lisha@fetoto.com', 'mail.fetoto.com', '');
			$mailer[] = array(10, 'like', 'susisoy', 'LiKe', 'like@fotete.com', 'mail.fotete.com', '');
		} elseif ($label == 2) {
			$mailer[] = array(10, 'buniaoku', 'susisoy', '布尿裤', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '布尿裤', 'buniaoku@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '布尿裤专店', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '布尿裤专店', 'buniaoku@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(05, 'buniaoku', 'susisoy', 'BuNiaoKu', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');
			$mailer[] = array(05, 'buniaoku', 'susisoy', 'BuNiaoKu', 'buniaoku@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '天使', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '天使', 'buniaoku@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '不尿裤', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', '不尿裤', 'buniaoku@fotete.com', 'mail.fotete.com', '');
		} elseif ($label == 4) {
			$mailer[] = array(10, 'fotete', 'susisoy', '沸淘淘', 'fotete@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'fetoto', 'susisoy', '沸淘淘', 'fetoto@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'fotete', 'susisoy', 'FOTETE', 'fotete@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'fetoto', 'susisoy', 'FETOTO', 'fetoto@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'fotete', 'susisoy', '话费充值', 'fotete@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'fetoto', 'susisoy', '话费充值', 'fetoto@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'admin', 'susisoy', '小店充值', 'admin@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'admin', 'susisoy', 'ADMIN', 'admin@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'ad', 'susisoy', '淘宝充值', 'ad@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'ad', 'susisoy', 'AD', 'ad@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'email', 'susisoy', '在线充值', 'email@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'email', 'susisoy', 'EMAIL', 'email@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'qq', 'susisoy', '在线充值', 'qq@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'qq', 'susisoy', 'EMAIL', 'qq@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'buniaoku', 'susisoy', '在线充值', 'buniaoku@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', 'EMAIL', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'product', 'susisoy', '电话充值', 'product@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'product', 'susisoy', 'PRODUCT', 'product@fetoto.com', 'mail.fetoto.com', '');
		} elseif ($label == 5) {
			$mailer[] = array(10, 'fotete', 'susisoy', '沸淘淘', 'fotete@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'fetoto', 'susisoy', '沸淘淘', 'fetoto@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'fotete', 'susisoy', 'FOTETE', 'fotete@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'fetoto', 'susisoy', 'FETOTO', 'fetoto@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'fotete', 'susisoy', 'QQ充值', 'fotete@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'fetoto', 'susisoy', 'QQ充值', 'fetoto@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(5, 'admin', 'susisoy', '小店充值', 'admin@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'admin', 'susisoy', 'ADMIN', 'admin@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(5, 'ad', 'susisoy', '淘宝充值', 'ad@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'ad', 'susisoy', 'AD', 'ad@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(5, 'email', 'susisoy', '在线充值', 'email@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'email', 'susisoy', 'EMAIL', 'email@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(5, 'qq', 'susisoy', '在线充值', 'qq@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'qq', 'susisoy', 'EMAIL', 'qq@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'buniaoku', 'susisoy', 'QQ在线', 'buniaoku@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'buniaoku', 'susisoy', 'EMAIL', 'buniaoku@fetoto.com', 'mail.fetoto.com', '');

			$mailer[] = array(10, 'product', 'susisoy', 'QQ充值', 'product@fotete.com', 'mail.fotete.com', '');
			$mailer[] = array(10, 'product', 'susisoy', 'QQ服务', 'product@fetoto.com', 'mail.fetoto.com', '');
		}

		// ======================================================================
		$m = array();

		foreach ($mailer as $key => $value) {
			$m = array_pad($m, count($m) + $value[0], $value);
		}

		shuffle($m);

		return $m;
	}

	/**
	 * 邮件内容定义
	 *
	 * @param int $label
	 * @return array
	 */
	static function message($label) {
		$title = $message = array();

		if ($label == 1) {
			$title[] = array('weight' => 10, 'title' => '网络解决方案与采购'); // 发送时，title 可能会自动附加“AD”、“FW”、“转发”等字样。
			$title[] = array('weight' => 10, 'title' => '华为金牌代理报价');
			$title[] = array('weight' => 10, 'title' => '华为网络解决方案与采购');
			$title[] = array('weight' => 10, 'title' => '华为产品报价');
			$title[] = array('weight' => 10, 'title' => '致华为渠道的一封信');
			$title[] = array('weight' => 10, 'title' => '华为渠道报价');
			$title[] = array('weight' => 10, 'title' => '网络设备采购参考');
			$title[] = array('weight' => 10, 'title' => '北京华中网络华为全系报价');
			$title[] = array('weight' => 10, 'title' => '华为产品白皮书');
			$title[] = array('weight' => 10, 'title' => '华为设备采购白皮书');
			$title[] = array('weight' => 10, 'title' => '华为渠道报价参考');
			$title[] = array('weight' => 10, 'title' => '也许今后您将多一位合作伙伴');
			$title[] = array('weight' => 10, 'title' => '可靠的华为报价');
			$title[] = array('weight' => 10, 'title' => '华为产品行情');
			$title[] = array('weight' => 10, 'title' => '华为全系产品金牌代理');
			$title[] = array('weight' => 05, 'title' => '看一下华为各产品的报价吧');
			$title[] = array('weight' => 10, 'title' => '一份华为热销产品报价');
			$title[] = array('weight' => 10, 'title' => '网络设备渠道报价');
			$title[] = array('weight' => 10, 'title' => '致网络设备采购者的一封信');
			$title[] = array('weight' => 10, 'title' => '网络设备热销产品一览');
			$title[] = array('weight' => 10, 'title' => '华为报价一览');
			$title[] = array('weight' => 10, 'title' => 'H3C、华为产品一览');
			$title[] = array('weight' => 10, 'title' => 'H3C、华为价格参考');
			$title[] = array('weight' => 10, 'title' => '愿与您携手共步在华为的路上');
			$title[] = array('weight' => 10, 'title' => '北京华中网络华为金牌报价');
			$title[] = array('weight' => 10, 'title' => '华为金牌代理渠道报价参考');
			$title[] = array('weight' => 10, 'title' => '华为金牌代理报价一览');
			$title[] = array('weight' => 10, 'title' => '承接网络组建等项目，有着政府科研等部门机构项目经验！');
			$title[] = array('weight' => 10, 'title' => '承接网络组建等项目，有丰富的政府科研等部门机构项目经验！');

			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'ITAD-1.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-2.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-3.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'ITAD-4.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-5.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-6.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'ITAD-7.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-8.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-9.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'ITAD-10.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-11.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'ITAD-12.html');
		} elseif ($label == 2) {
			$title[] = array('weight' => 10, 'title' => '给宝宝健康的成长');
			$title[] = array('weight' => 10, 'title' => '致宝宝家长的一封信');
			$title[] = array('weight' => 10, 'title' => '布尿裤淘宝专店');
			$title[] = array('weight' => 10, 'title' => '祝宝宝健康成长');
			$title[] = array('weight' => 10, 'title' => '穿上布尿裤，弃掉纸尿裤！');
			$title[] = array('weight' => 10, 'title' => '给宝宝准备好了吗？');
			$title[] = array('weight' => 10, 'title' => '你家有宝宝吗？');

			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'BUNIAOKU-1.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'BUNIAOKU-1.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'BUNIAOKU-2.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'BUNIAOKU-2.html');
		} elseif ($label == 4) {
			$title[] = array('weight' => 6, 'title' => '话费充值便宜了');
			$title[] = array('weight' => 6, 'title' => '话费充值');
			$title[] = array('weight' => 6, 'title' => '话费充值超低价');
			$title[] = array('weight' => 6, 'title' => '话费充值赚好评');
			$title[] = array('weight' => 10, 'title' => '移动充值');
			$title[] = array('weight' => 10, 'title' => '电信话费充值');
			$title[] = array('weight' => 10, 'title' => '移动话费充值');
			$title[] = array('weight' => 10, 'title' => '联通充值');
			$title[] = array('weight' => 10, 'title' => '淘宝充值');
			$title[] = array('weight' => 10, 'title' => '淘宝在线充值');
			$title[] = array('weight' => 10, 'title' => '淘宝话费充值');
			$title[] = array('weight' => 10, 'title' => '在线话费充值');
			$title[] = array('weight' => 10, 'title' => '在线充值');
			$title[] = array('weight' => 10, 'title' => '手机充值');
			$title[] = array('weight' => 10, 'title' => '手机充值便宜了');
			$title[] = array('weight' => 10, 'title' => '手机在线充值');
			$title[] = array('weight' => 10, 'title' => '在线充值便宜方便');
			$title[] = array('weight' => 10, 'title' => '网上充值');
			$title[] = array('weight' => 10, 'title' => '网上话费充值');
			$title[] = array('weight' => 10, 'title' => '网上充值便宜方便');

			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'CARD-1.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'CARD-2.html');
		} elseif ($label == 5) {
			$title[] = array('weight' => 10, 'title' => 'QQ币（点）、游戏卡购买充值');
			$title[] = array('weight' => 10, 'title' => 'QQ增值服务');
			$title[] = array('weight' => 10, 'title' => 'QQ币（点）、QQ会员、游戏卡购买充值');
			$title[] = array('weight' => 10, 'title' => 'QQ增值服务在线充值');
			$title[] = array('weight' => 10, 'title' => '腾讯增值服务');
			$title[] = array('weight' => 10, 'title' => 'QQ（币、点、会员、游戏）');
			$title[] = array('weight' => 10, 'title' => '腾讯QQ（币、点、会员、游戏）');
			$title[] = array('weight' => 5, 'title' => 'QQ堂');
			$title[] = array('weight' => 5, 'title' => 'QQ币（点）');
			$title[] = array('weight' => 10, 'title' => '淘宝店QQ增值服务直充');
			$title[] = array('weight' => 10, 'title' => 'QQ增值服务直充');
			$title[] = array('weight' => 10, 'title' => 'QQ直充');
			$title[] = array('weight' => 10, 'title' => 'QQ服务直充');
			$title[] = array('weight' => 10, 'title' => '淘宝QQ服务直充');
			$title[] = array('weight' => 10, 'title' => '淘宝店QQ服务直充');

			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_IMG, 'content' => 'QQ.html');
			$message[] = array('weight' => 10, 'mode' => self::EDM_MODE_NONE, 'content' => 'QQ.html');
		}

		// ======================================================================
		$t = array();

		foreach ($title as &$item) {
			$t = array_pad($t, count($t) + $item['weight'], $item['title']);
		}

		shuffle($t);

		// ======================================================================
		$m = array();

		foreach ($message as &$item) {
			$m = array_pad($m, count($m) + $item['weight'], array('mode' => $item['mode'], 'title' => $t[array_rand($t)], 'content' => $item['content']));
		}

		shuffle($m);

		return $m;
	}
}